<template>
  <div class="searchGoods">
    <!-- 顶部导航 -->
    <van-nav-bar
      title="搜索页"
      left-text="返回"
      right-text="..."
      left-arrow
      @click-left="$router.go(-1)"
    />

    <!-- 排序 -->
    <div class="paixu">
      <span
        v-for="(item, index) in paixuArr"
        :key="index"
        @click="qiehuan(index)"
        :class="{ active: curreIndex == index }"
      >
        {{ item }}
      </span>
    </div>

    <!-- 店铺列表 -->
    <div
      @click="toDetail(item)"
      class="shopping"
      v-for="(item, index) in list"
      :key="index"
    >
      <div class="left">
        <div class="img">
          <img :src="item.picUrl" alt="" />
        </div>
      </div>
      <div class="right">
        <div class="text">
          <h3>{{ item.name }}</h3>
          <span>{{ item.minPriceTip }}</span>
          <span>{{ item.minPriceTip }}</span>
          <span>{{ item.deliveryTimeTip }}</span>
          <span>{{ item.distance }}</span>
          <span>{{ item.wmPoiScore }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      curreIndex: 0,
      paixuArr: ["综合排序", "距离最近", "销量最高", "筛选"],
      shoppingArr: [],
    };
  },

  mounted() {
    //接收search传过来的数据
    this.list = this.$route.query.searchkey;
    console.log(this.list);
  },
  methods: {
    qiehuan(index) {
      if (index == 1) {
        this.shoppingArr.sort((a, b) => {
          return a.wmPoiScore - b.wmPoiScore;
        });
      }
      if (index == 2) {
        this.shoppingArr.sort((a, b) => {
          return b.wmPoiScore - a.wmPoiScore;
        });
      }
      if (index == 3) {
        this.shoppingArr.sort((a, b) => {
          return a.wmPoiScore - b.wmPoiScore;
        });
      }
    },
    toDetail(item) {
      //跳转到详情页
      this.$router.push("/detail/" + item.mtWmPoiId);
    },
  },
};
</script>

<style lang="scss" scoped>
.shopping {
  width: 100%;
  height: 150px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    width: 30%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .img {
      width: 80%;
      height: 80%;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .right {
    width: 70%;
    height: 100%;
    .text {
      width: 100%;
      height: 50px;

      margin-top: 15px;
    }

    span {
      padding-left: 15px;
    }
  }
}
.paixu {
  width: 100%;
  height: 30px;
  margin-top: 10px;
  display: flex;
  justify-content: space-around;
  align-items: center;

  .active {
    color: deepskyblue;
  }
}

.ban {
  display: flex;
  justify-content: center;
  align-items: center;
}

.banner {
  width: 95%;
  height: 110px;
  margin-top: 20px;
  border-radius: 30px;

  img {
    width: 100%;
    height: 100%;
    border-radius: 20px;
  }
}
</style>